package com.demoworld;

import com.demoworld.impl.MessagePrinter;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ClassPathXmlApplicationContext;

@Configuration
@ComponentScan
public class Startup {
    //applicationContext.xml 中的bean 配置可以删除
//    public static void main(String[] args) {
//        ApplicationContext context = new AnnotationConfigApplicationContext(Startup.class);
//        MessagePrinter printer = context.getBean(MessagePrinter.class);
//        printer.printMessage();
//    }
//
//    需要开启 applicationContext.xml 中的bean配置
    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        ((ClassPathXmlApplicationContext) context).refresh();
        MessagePrinter printer = context.getBean(MessagePrinter.class);
        printer.printMessage();
    }
}
